package com.rk.admin.controller;
import com.rk.admin.aop.SystemControllerLog;
import com.rk.admin.aop.VisCongtrollerApi;
import com.rk.admin.domain.Particle;
import com.rk.admin.service.ParticleService;
import com.rk.admin.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Api(tags = "人才培养")
@RestController
@CrossOrigin //前后端分离配置跨域访问
@RequestMapping("/particle")
public class ParticleController {

    @Autowired
    private ParticleService particleService;



    @ApiOperation(("查询人才培养后n条数据"))
    @ApiImplicitParams({
            @ApiImplicitParam(name = "count",value = "查询数量",example = "5"),
    })
    //@SystemControllerLog(description = "访问主界面")
    @VisCongtrollerApi
    @GetMapping("/findcount")
    public CommonResult limitpage(@RequestParam("count") int count){
        return CommonResult.success(particleService.findcount(count));

    }


    @ApiOperation(("分页查询本科生"))
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "分页起始页码",required = true,example = "1"),
            @ApiImplicitParam(name = "limit",value = "每页数据条数",required = true,example = "5"),
            @ApiImplicitParam(name = "title",value = "文章标题",example = "榆林市"),
    })
    @GetMapping("/findPageBen")
    public CommonResult findPageBen(Integer page,Integer limit, String title){
        //1 本科生
        return CommonResult.success(particleService.selectPage(page,limit,title,1));
    }



    @ApiOperation(("分页查询研究生"))
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "分页起始页码",required = true,example = "1"),
            @ApiImplicitParam(name = "limit",value = "每页数据条数",required = true,example = "5"),
            @ApiImplicitParam(name = "title",value = "文章标题",example = "榆林市"),
    })
    @GetMapping("/findPageYan")
    public CommonResult findPage(Integer page,Integer limit, String title){
        //2  研究生
        return CommonResult.success(particleService.selectPage(page,limit,title,2));
    }




//    /**
//     * 添加文章
//     * @param particle
//     * @return
//     */
//    @SystemControllerLog(description ="添加人才培养本科生文章")
//    @ApiOperation("添加本科生文章")
//    @PostMapping("/addben")
//    public CommonResult add(@RequestBody Particle particle) {
//        System.out.println(particle.toString());
//        Boolean flag = particleService.addben(particle);
//        if(flag){
//            return CommonResult.success(flag);
//        }else {
//            return CommonResult.failed("添加失败!!");
//        }
//    }
//
//
//    /**
//     * 添加文章
//     * @param particle
//     * @return
//     */
//    @SystemControllerLog(description ="添加人才培养研究生文章")
//    @ApiOperation("添加研究生文章")
//    @PostMapping("/addyan")
//    public CommonResult addyan(@RequestBody Particle particle) {
//        System.out.println(particle.toString());
//        Boolean flag = particleService.addyan(particle);
//        if(flag){
//            return CommonResult.success(flag);
//        }else {
//            return CommonResult.failed("添加失败!!");
//        }
//    }


    /**
     * 通过id删除
     * @param id
     * @return
     */
    @SystemControllerLog(description ="删除人才培养文章")
    @ApiOperation("删除文章")
    @PostMapping("/deletebyid")
    public CommonResult deletebyid(@RequestParam("id")Integer id){
        Boolean flag = particleService.deleteById(id);
        if(flag){//删除成功
            return CommonResult.success(flag);
        }else {
            return CommonResult.failed("删除失败!");
        }
    }


    /**
     * 通过id查询文章
     */
    @ApiOperation("通过id查询文章")
    @GetMapping("/findbyid")
    public CommonResult findbyid(@RequestParam("id") Integer id){
        List<Particle> list=new ArrayList<>();
        list.add(particleService.findbyId(id));
        return  CommonResult.success(list);
    }


    /**
     * 通过id修改文章
     */
    @SystemControllerLog(description ="通过id修改(研究生/本科生)人才培养文章")
    @ApiOperation("通过id修改(研究生/本科生))文章")
    @PostMapping("/updatebyid")
    public CommonResult updatebyid(@RequestBody Particle particle){
        //设置修改时间
        particle.setEdittime(new Date());
        Boolean flag = particleService.updatebyId(particle);

        if(flag){//如果修改成功
            return CommonResult.success(flag);
        }else {
            return CommonResult.failed("修改失败!");
        }
    }

}
